/*
package com.awonsome.auth.security.core.userdetails.user;

import com.awonsome.admin.api.UserFeignClient;
import com.awonsome.admin.api.dto.UserAuthDTO;
import com.awonsome.common.core.result.Result;
import com.awonsome.common.core.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;

*/
/**
 * @author yangdejun
 * @date 2022/1/23 16:16
 *//*


@Service("sysUserDetailsService")
@Slf4j
@RequiredArgsConstructor
public class SysUserDetailsServiceImpl implements UserDetailsService {

    private final UserFeignClient userFeignClient;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUserDetails userDetails = null;
        Result<UserAuthDTO> result = userFeignClient.getUserByUsername(username);
        if (Result.isSuccess(result)) {
            UserAuthDTO user = result.getData();
            if (Objects.nonNull(user)) {
                userDetails = new SysUserDetails(user);
            }
        }
        if (Objects.isNull(userDetails)) {
            throw new RuntimeException(ResultCode.SYSTEM_EXECUTION_ERROR.getMsg());
        } else if (!userDetails.isEnabled()) {
            throw new RuntimeException("该账号已被禁用!");
        } else if (!userDetails.isAccountNonLocked()) {
            throw new RuntimeException("该账号已被锁定！");
        } else if (!userDetails.isAccountNonExpired()) {
            throw new RuntimeException("该账号已过期！");
        }
        return userDetails;
    }
}
*/
